package com.ktwlsoft.fundmanage.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;

@Getter
@Setter
@MappedSuperclass
public abstract class BaseFundRecord extends BaseEntity {

    /**
     * 主键
     */
    @ApiModelProperty("主键")
    @Id
    @Column(name = "f_code", columnDefinition = "bigint(30) NOT NULL COMMENT '主键'")
    protected Long fCode;

    @ApiModelProperty("流水号")
    @Column(columnDefinition = "bigint(30) default 0 comment '流水号'")
    protected Long flowCode=0L;

    @ApiModelProperty("收据单号")
    @Column(columnDefinition = "varchar(30) default null comment '收据单号'")
    protected String receiptCode;

    /**
     * 划款单号
     */
    @ApiModelProperty("划款单号")
    @Column(columnDefinition = "bigint(30) default 0 comment '划款单号'")
    private Long dnCode = 0L;

    /**
     * 交易编号
     */
    @ApiModelProperty("案件编号")
    @NotNull
    @Column(columnDefinition = "bigint(30) default 0 comment '案件编号'")
    protected Long tsCode;

    /**
     * Activiti 工作流实例Id
     */
    @ApiModelProperty("工作流id")
    @Column(columnDefinition = "varchar(10) default null comment '流程实例id' ")
    protected String flowInstanceId;

    /**
     * 转账金额(万元)
     */
    @ApiModelProperty("转账金额(万元)")
    @Column(columnDefinition = "decimal(16,8) DEFAULT 0 COMMENT '转账金额(万元)'")
    protected BigDecimal amount;

    @ApiModelProperty("类型，全款、首付、贷款、退款")
    @Enumerated(EnumType.STRING)
    protected Type type;

    /**
     * 是否曾退回
     */
    @ApiModelProperty("是否曾退回")
    @Column(columnDefinition = "bit DEFAULT 0 COMMENT '是否曾退回'")
    protected boolean isReturn = false;

    /**
     * 是否撤销
     */
    @ApiModelProperty("是否撤销")
    @Column(name = "is_revoke", columnDefinition = "bit DEFAULT 0 COMMENT '是否撤销'")
    protected boolean isRevoke = false;

    /**
     * 经办人Id
     */
    @ApiModelProperty("经办人Id，不得超过50字符")
    @Column(name = "user_id", length = 50, columnDefinition = "varchar(30) default null comment '经办人id'")
    @Size(max = 50, message = "经办人id,不得超过50字符")
    protected String userId;

    /**
     * 经办人姓名
     */
    @ApiModelProperty("经办人姓名，不得超过30字符")
    @Column(name = "user_name", length = 30, columnDefinition = "varchar(10) default null comment '经办人姓名'")
    @Size(max = 30, message = "经办人姓名，不得超过30字符")
    protected String userName;

    @ApiModelProperty("备注")
    @Column(length = 100, columnDefinition = "varchar(50) default null comment '备注'")
    protected String remark;

    /**
     * 凭证打印次数
     */
    @ApiModelProperty("凭证打印次数")
    @Column(name = "print_count", columnDefinition = "tinyint(4) DEFAULT 0 COMMENT '凭证打印次数'")
    private Integer printCount=0;

    @ApiModelProperty("付款方式")
    @Column(name = "pay_method", length = 50, columnDefinition = "varchar(20) default null comment '付款方式'")
    private String payInMethod;

    @ApiModelProperty("使用状态")
    @Enumerated(EnumType.STRING)
    @Column(length = 30 , columnDefinition = "varchar(30) default 'NORMAL' COMMENT '使用状态'")
    private State state;

    /**
     * 付费方式
     */
    public enum PayInMethod {
        /**
         * 出账
         */
        CHASH("现金"),
        /**
         * POS
         */
        POS("POS机"),
        /**
         * 转账
         */
        TRANS("转账"),
        /**
         * 银行贷款
         */
        LOAN("银行贷款"),
        /**
         * 支票
         */
        CHECK("支票"),
        /**
         * 其他
         */
        OTHER("其他");

        @Getter
        private final String name;

        PayInMethod(final String name) {
            this.name = name;
        }
    }

    /**
     * 记录类型
     */
    public enum Type {
        /**
         * 全款
         */
        FULLPAY("全款"),
        /**
         * 首付
         */
        DOWNPAY("首付"),
        /**
         * 贷款
         */
        LOAN("贷款");

        private final String name;

        Type(final String name) {
            this.name = name;
        }
    }

    /**
     * 状态
     */
    public enum State {
        /**
         * 正常
         */
        NORMAL,
        /**
         * 撤回
         */
        CANCEL,
        /**
         * 撤回后被处理
         */
        CANCEL_HANDLED;
    }
}
